package org.holynite.fieldmanage.managed.model

import org.holynite.fieldmanage.ejbs.AdministratorManagement
import org.holynite.fieldmanage.entities.Administrator

import javax.annotation.PostConstruct
import javax.ejb.EJB
import javax.faces.bean.ManagedBean
import javax.faces.bean.ViewScoped

/**
 * Created by midnite on 15/1/31.
 */
@ManagedBean
@ViewScoped
class AdministratorsBean implements Serializable {
    List<Administrator> admins

    @EJB(beanName = "adminControl")
    AdministratorManagement adminService

    AdministratorsBean() {
        admins = []
    }

    @PostConstruct
    void initiate() {
        admins = adminService.listAdministrators("")
    }

    void reloadAdministrators(String keyword) {
        admins = adminService.listAdministrators(keyword)
    }

    Administrator findAdministrator(String adminId) {
        admins.find { it.workdId.equals(adminId) }
    }
}
